<template>
  <div class="product">
    <!-- 物品介绍图片 -->
    <img :src="shopItem.shopPic" alt="">
    <div class="product-details">
      <!-- 购买物品的名称 -->
      <h2>{{ shopItem.shopName }}</h2>
      <!-- 物品价格 -->
      <p>${{ shopItem.price }}</p>
      <!-- 控制购买物品数量的按钮 -->
      <div class="quantity">
        <!-- 减少购买数量按钮 -->
        <button type="button" :disabled="shopItem.count <= 1" @click="shopItem.count--">-</button>
        <!-- 数量显示输入框 -->
        <input
        type="text"
        v-model="shopItem.count"
        @change="() => {shopItem.count = shopItem.count < 1 ? 1 : shopItem.count}">
        <!-- 增加购买数量按钮 -->
        <button type="button" :disabled="shopItem.count >= shopItem.stock " @click="shopItem.count++">+</button>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { type IshopInfo } from '@/types/shop';
import { ref } from 'vue';

const props = defineProps<{
  item: IshopInfo;
}>();
const shopItem = ref<IshopInfo>(props.item);
console.log(shopItem);

</script>

<style lang="scss">
.product {
  display: flex;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid #ddd;
}

.product img {
  width: 200px!important;
  height: 200px!important;
  margin-right: 20px;
  border: 1px solid rgb(104, 165, 226);
}

.product-details {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.product-details h2 {
  margin: 0;
}

.product-details p {
  font-size: 1.2em;
  font-weight: bold;
  color: #333;
}

/* 数量调节按钮 */
.quantity {
  display: flex;
  align-items: center;
}

.quantity button {
  padding: 5px 10px;
  margin: 0 5px;
  background-color: #2f4fba;
  color: white;
  border: none;
  cursor: pointer;
}

.quantity button:hover {
  background-color: #2ec28b;
}

.quantity input {
  width: 40px;
  text-align: center;
}

button:disabled:hover,
button:disabled {
  background-color: #da222c;
}
</style>
